home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
a_utils
/
expanded.lha
/
expanded
/
src
/
List.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
21KB
|
1,007 lines
//
// Linear-Affine-Projective Geometry Package
//
// List.C
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Implementation of the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#include "List.h"
// This implementation of lists is a prime candidate for templates
// if it is implemented using a C++ compiler that supports them!
// Since lists are defined to store and return elements (instead
// of pointers to elements), the code needs to be duplicated
// for each class. Using any sort of inheritance would probably be
// more trouble than it is worth in this instance.
// ***********************************************************************
// ***********************************************************************
//
// ScalarList
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
ScalarList::ScalarList(ScalarList &t)
{
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Scalar[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
}
// ***********************************************************************
ScalarList::ScalarList(int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Scalar[size];
} else {
list = local;
}
for (int i = 0; i < n; i++) {
list[i] = 0.0;
}
}
// ***********************************************************************
ScalarList::ScalarList(Scalar s, int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Scalar[size];
} else {
list = local;
}
for (int i = 0; i < n; i++) {
list[i] = s;
}
}
// ***********************************************************************
ScalarList::ScalarList(Scalar s)
{
list = local;
size = 1;
list[0] = s;
}
// ***********************************************************************
ScalarList::ScalarList(Scalar s1, Scalar s2)
{
list = local;
size = 2;
list[0] = s1;
list[1] = s2;
}
// ***********************************************************************
ScalarList::ScalarList(Scalar s1, Scalar s2, Scalar s3)
{
list = local;
size = 3;
list[0] = s1;
list[1] = s2;
list[2] = s3;
}
// ***********************************************************************
ScalarList::ScalarList(Scalar s1, Scalar s2, Scalar s3, Scalar s4)
{
list = local;
size = 4;
list[0] = s1;
list[1] = s2;
list[2] = s3;
list[3] = s4;
}
// ***********************************************************************
Scalar& ScalarList::operator[](int n)
{
if ((n < 0) || (n >= size)) {
errh.ErrorExit("Scalar& ScalarList::operator[](int)",
"Index is out of range", ErrVal("Index = ", n), *this);
}
return list[n];
}
// ***********************************************************************
ScalarList ScalarList::operator+(ScalarList &t)
{
int i;
int newsize = size + t.Length();
ScalarList retval(newsize);
for (i = 0; i < size; i++) {
retval[i] = (*this)[i];
}
for (i = size; i < newsize; i++) {
retval[i] = t[i - size];
}
return (retval);
}
// ***********************************************************************
ScalarList ScalarList::operator*(int i)
{
int newsize = i * size;
ScalarList retval(newsize);
for (int k = 0; k < i; k++) {
for (int j = 0; j < size; j++) {
retval[(k * size) + j] = list[j];
}
}
return (retval);
}
// ***********************************************************************
ScalarList& ScalarList::operator=(ScalarList &t)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete list;
}
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Scalar[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
return (*this);
}
// ***********************************************************************
//
// Destructor
//
ScalarList::~ScalarList(void)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete list;
}
}
// ***********************************************************************
//
// To do debug printing:
//
void ScalarList::debug_out(ostream &c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "Scalar list\n";
c << ibloc << "Number of elements: " << size << "\n";
if (size > 0) {
c << ibloc << "Elements:";
c << ibloc;
for (int j = 0; j < size; j++) {
if (j % 4 == 0) {c << "\n" << ibloc;}
c << list[j] << " ";
}
c << "\n";
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************
// ***********************************************************************
//
// IntList
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
IntList::IntList(IntList &t)
{
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new int[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
}
// ***********************************************************************
IntList::IntList(int s)
{
size = s;
if (size > MAX_LOCAL_LIST) {
list = new int[size];
} else {
list = local;
}
for (int i = 0; i < s; i++) {
list[i] = 0;
}
}
// ***********************************************************************
IntList::IntList(int val, int s)
{
size = s;
if (size > MAX_LOCAL_LIST) {
list = new int[size];
} else {
list = local;
}
for (int i = 0; i < s; i++) {
list[i] = val;
}
}
// ***********************************************************************
IntList::IntList(int s1, int s2, int s3)
{
list = local;
size = 3;
list[0] = s1;
list[1] = s2;
list[2] = s3;
}
// ***********************************************************************
IntList::IntList(int s1, int s2, int s3, int s4)
{
list = local;
size = 4;
list[0] = s1;
list[1] = s2;
list[2] = s3;
list[3] = s4;
}
// ***********************************************************************
int& IntList::operator[](int n)
{
if ((n < 0) || (n >= size)) {
errh.ErrorExit("int& IntList::operator[](int)",
"Index is out of range", ErrVal("Index = ", n), *this);
}
return list[n];
}
// ***********************************************************************
IntList IntList::operator+(IntList &t)
{
int i;
int newsize = size + t.Length();
IntList retval(newsize);
for (i = 0; i < size; i++) {
retval[i] = (*this)[i];
}
for (i = size; i < newsize; i++) {
retval[i] = t[i - size];
}
return (retval);
}
// ***********************************************************************
IntList IntList::operator*(int i)
{
int newsize = i * size;
IntList retval(newsize);
for (int k = 0; k < i; k++) {
for (int j = 0; j < size; j++) {
retval[(k * size) + j] = list[j];
}
}
return (retval);
}
// ***********************************************************************
IntList& IntList::operator=(IntList &t)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete list;
}
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new int[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
return (*this);
}
// ***********************************************************************
//
// Destructor
//
IntList::~IntList(void)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete list;
}
}
// ***********************************************************************
//
// To do debug printing:
//
void IntList::debug_out(ostream &c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "Integer list\n";
c << ibloc << "Number of elements: " << size << "\n";
if (size > 0) {
c << ibloc << "Elements:";
c << ibloc;
for (int j = 0; j < size; j++) {
if (j % 4 == 0) {c << "\n" << ibloc;}
c << list[j] << " ";
}
c << "\n";
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************
// ***********************************************************************
//
// GeObList
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
GeObList::GeObList(GeObList &t)
{
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new GeOb[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
}
// ***********************************************************************
GeObList::GeObList(int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new GeOb[size];
} else {
list = local;
}
}
// ***********************************************************************
GeObList::GeObList(GeOb &s, int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new GeOb[size];
} else {
list = local;
}
for (int i = 0; i < n; i++) {
list[i] = s;
}
}
// ***********************************************************************
GeObList::GeObList(GeOb &s)
{
list = local;
size = 1;
list[0] = s;
}
// ***********************************************************************
GeObList::GeObList(GeOb &s1, GeOb &s2)
{
list = local;
size = 2;
list[0] = s1;
list[1] = s2;
}
// ***********************************************************************
GeObList::GeObList(GeOb &s1, GeOb &s2, GeOb &s3)
{
list = local;
size = 3;
list[0] = s1;
list[1] = s2;
list[2] = s3;
}
// ***********************************************************************
GeObList::GeObList(GeOb &s1, GeOb &s2, GeOb &s3, GeOb &s4)
{
list = local;
size = 4;
list[0] = s1;
list[1] = s2;
list[2] = s3;
list[3] = s4;
}
// ***********************************************************************
GeOb& GeObList::operator[](int n)
{
if ((n < 0) || (n >= size)) {
errh.ErrorExit("GeOb& GeObList::operator[](int)",
"Index is out of range", ErrVal("Index = ", n), *this);
}
return list[n];
}
// ***********************************************************************
GeObList GeObList::operator+(GeObList &t)
{
int i;
int newsize = size + t.Length();
GeObList retval(newsize);
for (i = 0; i < size; i++) {
retval[i] = (*this)[i];
}
for (i = size; i < newsize; i++) {
retval[i] = t[i - size];
}
return (retval);
}
// ***********************************************************************
GeObList GeObList::operator*(int i)
{
int newsize = i * size;
GeObList retval(newsize);
for (int k = 0; k < i; k++) {
for (int j = 0; j < size; j++) {
retval[(k * size) + j] = list[j];
}
}
return (retval);
}
// ***********************************************************************
GeObList& GeObList::operator=(GeObList &t)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new GeOb[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
return (*this);
}
// ***********************************************************************
//
// Destructor
//
GeObList::~GeObList(void)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
}
// ***********************************************************************
//
// To do debug printing:
//
void GeObList::debug_out(ostream &c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "GeOb list\n";
c << ibloc << "Number of elements: " << size << "\n";
if (size > 0) {
c << ibloc << "Elements:\n";
for (int j = 0; j < size; j++) {
list[j].debug_out(c, indent + ERR_IND);
}
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************
// ***********************************************************************
//
// SpaceList
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
SpaceList::SpaceList(SpaceList &t)
{
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Space[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
}
// ***********************************************************************
SpaceList::SpaceList(int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Space[size];
} else {
list = local;
}
}
// ***********************************************************************
SpaceList::SpaceList(Space &s, int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Space[size];
} else {
list = local;
}
for (int i = 0; i < n; i++) {
list[i] = s;
}
}
// ***********************************************************************
SpaceList::SpaceList(Space &s)
{
list = local;
size = 1;
list[0] = s;
}
// ***********************************************************************
SpaceList::SpaceList(Space &s1, Space &s2)
{
list = local;
size = 2;
list[0] = s1;
list[1] = s2;
}
// ***********************************************************************
SpaceList::SpaceList(Space &s1, Space &s2, Space &s3)
{
list = local;
size = 3;
list[0] = s1;
list[1] = s2;
list[2] = s3;
}
// ***********************************************************************
SpaceList::SpaceList(Space &s1, Space &s2, Space &s3, Space &s4)
{
list = local;
size = 4;
list[0] = s1;
list[1] = s2;
list[2] = s3;
list[3] = s4;
}
// ***********************************************************************
Space& SpaceList::operator[](int n)
{
if ((n < 0) || (n >= size)) {
errh.ErrorExit("Space& SpaceList::operator[](int)",
"Index is out of range", ErrVal("Index = ", n), *this);
}
return list[n];
}
// ***********************************************************************
SpaceList SpaceList::operator+(SpaceList &t)
{
int i;
int newsize = size + t.Length();
SpaceList retval(newsize);
for (i = 0; i < size; i++) {
retval[i] = (*this)[i];
}
for (i = size; i < newsize; i++) {
retval[i] = t[i - size];
}
return (retval);
}
// ***********************************************************************
SpaceList SpaceList::operator*(int i)
{
int newsize = i * size;
SpaceList retval(newsize);
for (int k = 0; k < i; k++) {
for (int j = 0; j < size; j++) {
retval[(k * size) + j] = list[j];
}
}
return (retval);
}
// ***********************************************************************
SpaceList& SpaceList::operator=(SpaceList &t)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Space[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
return (*this);
}
// ***********************************************************************
//
// Destructor
//
SpaceList::~SpaceList(void)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
}
// ***********************************************************************
//
// To do debug printing:
//
void SpaceList::debug_out(ostream &c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "Space list\n";
c << ibloc << "Number of elements: " << size << "\n";
if (size > 0) {
c << ibloc << "Elements:\n";
for (int j = 0; j < size; j++) {
list[j].debug_out(c, indent + ERR_IND);
}
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************
// ***********************************************************************
//
// BasisList
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
BasisList::BasisList(BasisList &t)
{
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Basis[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
}
// ***********************************************************************
BasisList::BasisList(int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Basis[size];
} else {
list = local;
}
}
// ***********************************************************************
BasisList::BasisList(Basis &s, int n)
{
size = n;
if (size > MAX_LOCAL_LIST) {
list = new Basis[size];
} else {
list = local;
}
for (int i = 0; i < n; i++) {
list[i] = s;
}
}
// ***********************************************************************
BasisList::BasisList(Basis &s)
{
list = local;
size = 1;
list[0] = s;
}
// ***********************************************************************
BasisList::BasisList(Basis &s1, Basis &s2)
{
list = local;
size = 2;
list[0] = s1;
list[1] = s2;
}
// ***********************************************************************
BasisList::BasisList(Basis &s1, Basis &s2, Basis &s3)
{
list = local;
size = 3;
list[0] = s1;
list[1] = s2;
list[2] = s3;
}
// ***********************************************************************
BasisList::BasisList(Basis &s1, Basis &s2, Basis &s3, Basis &s4)
{
list = local;
size = 4;
list[0] = s1;
list[1] = s2;
list[2] = s3;
list[3] = s4;
}
// ***********************************************************************
Basis& BasisList::operator[](int n)
{
if ((n < 0) || (n >= size)) {
errh.ErrorExit("Basis& BasisList::operator[](int n)",
"Index is out of range", ErrVal("Index = ", n), *this);
}
return list[n];
}
// ***********************************************************************
BasisList BasisList::operator+(BasisList &t)
{
int i;
int newsize = size + t.Length();
BasisList retval(newsize);
for (i = 0; i < size; i++) {
retval[i] = (*this)[i];
}
for (i = size; i < newsize; i++) {
retval[i] = t[i - size];
}
return (retval);
}
// ***********************************************************************
BasisList BasisList::operator*(int i)
{
int newsize = i * size;
BasisList retval(newsize);
for (int k = 0; k < i; k++) {
for (int j = 0; j < size; j++) {
retval[(k * size) + j] = list[j];
}
}
return (retval);
}
// ***********************************************************************
BasisList& BasisList::operator=(BasisList &t)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
size = t.Length();
if (size > MAX_LOCAL_LIST) {
list = new Basis[size];
} else {
list = local;
}
for (int i = 0; i < size; i++) {
list[i] = t[i];
}
return (*this);
}
// ***********************************************************************
//
// Destructor
BasisList::~BasisList(void)
{
if ((list != NULL) && (size > MAX_LOCAL_LIST)) {
delete [size] list;
}
}
// ***********************************************************************
//
// To do debug printing:
void BasisList::debug_out(ostream &c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "Basis list\n";
c << ibloc << "Number of elements: " << size << "\n";
if (size > 0) {
c << ibloc << "Elements:\n";
for (int j = 0; j < size; j++) {
list[j].debug_out(c, indent + ERR_IND);
}
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************